<!--通行申请-->
<template>
  <div class="log">
    <basic-container>
      <avue-crud
          ref="crud"
          :data="tableData"
          :option="tableOption"
          :page.sync="page"
          :permission="permissionList"
          :table-loading="tableLoading"
          @on-load="getList"
          @search-reset="searchReset"
          @search-change="searchChange"
          @refresh-change="refreshChange"
          @size-change="sizeChange"
          @current-change="currentChange">
        <template slot="status" slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" type="primary">审批中</el-tag>
          <el-tag v-else-if="scope.row.status === 1" type="success">已通过</el-tag>
          <el-tag v-else-if="scope.row.status === 2" type="danger">已驳回</el-tag>
        </template>
        <template slot="menu" slot-scope="scope">
          <el-button
              class="filter-item"
              icon="el-icon-view"
              size="mini"
              type="warning"
              style="margin-bottom: 4px"
              @click.native="examine(scope.row)">查看审批
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>
<script>
import {mapGetters} from "vuex";
import {approvalObj} from "@/api/pass/approval";
import {GROUP_SEX, PASS_DETAILS} from '@/const/Dict'
import {PERSON_DETAILS, PERSON_OPERA} from "@/const/personDict";
import {APPROVAL_STATUS} from "@/const/approval";

export default {
  name: "approval",
  data() {
    return {
      tableData: [],
      searchForm: {},
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading: false,
      //单个分配
      timePlanName: [],
      currentrow: {},
      schid: '',
      chooseList: [],
      tableOption: {
        border: true,
        index: true,
        indexLabel: '序号',
        stripe: true,
        menuAlign: 'center',
        menuWidth: 138,
        menuType: 'button',
        align: 'center',
        emptyBtnText: '重置', //清空按钮文案
        refreshBtn: true,
        showClomnuBtn: false,
        searchSize: 'mini',
        searchMenuSpan: 6,
        labelWidth: "20%",
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        selection: false,
        reserveSelection: true,
        props: {
          label: 'label',
          value: 'value'
        },
        column: [
          {
            label: '人员id',
            prop: 'id',
            hide: true
          },
          {
            label: '姓名',
            prop: 'name',
            type: 'input',
            search: true,
          }, {
            label: '学号',
            prop: 'number',
            dicData: PASS_DETAILS,
          }, {
            label: '性别',
            prop: 'sex',
            type: 'select',
            search: true,
            dicData: GROUP_SEX,
            change: (value) => {
              if(value.value === ''){
                return;
              }
              this.searchForm.sex = value.value
              this.getList(this.page, this.searchForm)
            },
          },{
            label: '校区',
            prop: 'campusDeptArea',
            dicData: PERSON_DETAILS,
            editDisplay: false,
          },
          {
            label: '年级',
            prop: 'gradeName',
            search: false,
            type: 'select',
            dicData: PASS_DETAILS,
          },
          {
            label: '年级',
            prop: 'gradeId',
            search: true,
            type: 'select',
            hide: true,
            defaultExpandAll: true,
            dicUrl: '/admin/dept/PermissionTree',
            cascaderItem: ['deptName'],
            dicFormatter: (res) => {
              let gradeArr = res.data
              let value = []
              if(gradeArr.length> 0){
                for(let i of gradeArr){
                  if(i.typeNum == "2" && i.isLock === false){
                    value.push(i)
                  }
                }
                console.log(value)
                return value
              }
            },
            dicMethod: 'get',
            props: {
              label: 'name',
              value: 'id'
            },
            change: (value) => {
              if(value.value === ''){
                return;
              }
              this.searchForm.gradeId = value.value
              this.getList(this.page, this.searchForm)
            },
          },
          {
            label: '班级',
            prop: 'className',
            search: false,
            type: 'select',
            dicData: PASS_DETAILS,
          },
          {
            label: '班级',
            prop: 'deptName',
            search: true,
            filter: false,
            type: 'select',
            hide: true,
            defaultExpandAll: true,
            dicUrl: '/campus/sysdept/detpTree/{{key}}/1,2,3',
            dicFormatter: (res) => {
              return res.data[0].children;//返回字典的层级结构
            },
            dicMethod: 'get',
            props: {
              label: 'name',
              value: 'deptId',
            },
            change: (value) => {
              if(value.value === ''){
                return;
              }
              this.searchForm.classId = value.value
              this.getList(this.page, this.searchForm)
            },
          },
          {
            label: '学生属性',
            prop: 'identity',
            search: true,
            type: 'select',
            dicUrl: '/campus/identity/selectAll?groupNum=2',
            dicMethod: 'get',
            props: {
              label: 'name',
              value: 'name'
            },
            change: (value) => {
              if(value.value === ''){
                return;
              }
              this.searchForm.identity = value.value
              this.getList(this.page, this.searchForm)
            },
          },{
            label: '楼栋',
            prop: 'buildingName',
            search: false,
            dicData: PASS_DETAILS,
          },
          {
            label: '楼栋',
            prop: 'buildingId',
            hide: true,
            search: true,
            type: 'select',
            dicUrl: '/campus/building/selectAll',
            dicMethod: 'get',
            props: {
              label: 'buildingName',
              value: 'buildingName'
            },
            change: (value) => {
              if(value.value === ''){
                return;
              }
              this.searchForm.buildingName = value.value
              this.getList(this.page, this.searchForm)
            },
          },
          {
            label: '审批状态',
            prop: 'status',
            search: true,
            slot:true,
            type: 'select',
            dicData: APPROVAL_STATUS,
            change: (value) => {
              if(value.value === ''){
                return;
              }
              this.searchForm.status = value.value
              this.getList(this.page, this.searchForm)
            },
          },
          {
            width: 150,
            label: '申请时间',
            prop: 'createTime',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            addDisplay: false,
            editDisplay: false,
          }, {
            width: 100,
            label: '发起人',
            prop: 'createUser',
            dicData: PERSON_OPERA,
          },
        ]
      }
    }
  },
  computed: {
    ...mapGetters(['permissions']),
    permissionList() {
      return {
        delBtn: this.vaildData(this.permissions.sys_time_del, false),
      }
    }
  },
  methods: {
    //展示表格
    getList(page, params) {
      let param = this.$route.query;
      this.tableLoading = true
      approvalObj(Object.assign({
        descs: 'create_time',  //是否倒序
        current: page.currentPage,
        size: page.pageSize
      }, params,this.searchForm)).then(response => {
        this.tableData = response.data.data.records
        this.page.total = response.data.data.total
        this.tableLoading = false
      })
    },

    //查看审批跳转页面
    examine(row) {
      const src = `/pass/seeApproval`
      this.$router.push({
        path: src,
        query: {id: row.id}
      })
    },

    //搜索页面内容
    searchChange(form, done) {
      if (form.deptName !== undefined) {
        form.deptId = form.deptName
      }
      this.searchForm = form
      this.page.currentPage = 1
      this.getList(this.page, form)
      done()
    },

    //点击每页多少条会调size-change方法回调
    sizeChange(pageSize) {
      this.page.pageSize = pageSize
    },

    //点击页码会调用current-change方法回调当前页
    currentChange(current) {
      this.page.currentPage = current
    },
    refreshChange() {
      this.getList(this.page)
    },

    //清空时重置页面
    searchReset() {
      this.searchForm = {};
      this.getList(this.page)
    }
  }
}
</script>

<style scoped>
h4 {
  margin: 0;
}
/deep/.avue-crud__menu{
  display: none;
}
/deep/.el-form-item__label{
  text-align: left;
}
/deep/.avue-form__row{
  padding-left: 2px !important;
  padding-right: 36px!important;
}
/deep/.avue-form__menu--center{
  text-align: left;
}
/deep/.avue-form__menu--center .el-button{
  margin: 0 20px 0 0;
}
</style>
